package com.dragon.dragonshop.config;

import com.dragon.dragonshop.component.LoginHandleInterceptor;
import com.dragon.dragonshop.component.RememberMeInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyCustomConfig {

    @Bean
    public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
        return new WebMvcConfigurerAdapter() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new RememberMeInterceptor()).addPathPatterns("/");
                registry.addInterceptor(new LoginHandleInterceptor()).addPathPatterns("/**").
                        excludePathPatterns(
                                "/",
                                "/index.html",
                                "/register.html",
                                "/top-part.html",
                                "/search.html",
                                "/search-part.html",
                                "/user/*",
                                "/getVerifyCode");
            }

            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("index");
                registry.addViewController("/index.html").setViewName("index");
                registry.addViewController("/search-part.html").setViewName("search-part");
                registry.addViewController("/top-part.html").setViewName("top-part");
                registry.addViewController("/search.html").setViewName("search");
                registry.addViewController("/register.html").setViewName("register");
                registry.addViewController("/userimg-part.html").setViewName("userimg-part");
                registry.addViewController("/user/*/top-part.html").setViewName("top-part");
                registry.addViewController("/user/*/search-part.html").setViewName("search-part");
                registry.addViewController("/user/*/userimg-part.html").setViewName("userimg-part");
                registry.addViewController("/user/*/search.html").setViewName("search");
                registry.addViewController("/sortgoods.html").setViewName("sortgoods");
            }
        };
    }

}
